package com.fingard.dsp.bank.reqrespobj.statement;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextReader;

import java.text.ParseException;
import java.util.Date;

public class ReqQryStatement extends RequestBase {
	/*<ATSYH version="1.0">
 <TransReq>
   <BankCode>线路代码</BankCode>
   <TransType>QryStatement</TransType>
   <TransSeqID>025626713</TransSeqID>
   <TransTime>2015-04-2914:56:26</TransTime>
   <TransParam>
     <ActNum>1234567890123456</ActNum>
     <BusDate>yyyyMMdd</BusDate>
     <StatementType></StatementType>
   </TransParam>
 </TransReq>
</ATSYH>

-- 新华专用对账单
<ATSYH version="1.0">
	<TransReq>
		<BankCode>WJZF02</BankCode>
		<MoneyWay>2</MoneyWay>
		<TransType>ROA</TransType>
		<PageNO>1</PageNO>
		<PageSize>2000</PageSize>
		<TransSeqID>030441109</TransSeqID>
		<TransTime>2018-05-11 15:04:41</TransTime>
		<TransParam>
			<ActNum>123456789</ActNum>
			<DateToday>2018-07-21</DateToday>
		</TransParam>
	</TransReq>
</ATSYH>
*/

	/**账号*/
	public String actNum = "";
	
	/**对账单日期*/
	public String busDate = "";
	
	/** POS所属供应商 */
	public String channel = "";

	/** POS所属供应商 */
	public String askNumber = "";

	/** POS所属供应商 */
	public String statementNumber = "";

	/**上级账户 */
	public String higherLevelAct;

	/**
	 * 对账单类型 -- 
	 * 
	 * 5：实时单笔收款;
	 * 6：实时付款;
	 * 7：零余额扣款;
	 * 8：短信扣款;
	 * 9：POS机收款;
	 * A：短信回复扣款;
	 * B：电话语音扣款;
	 * CDE：移动收单，包括扫码支付、公众号支付、APP支付
	 * S：代收
	 * F：代付
	*/
	public String statementType = "";

    /**
     * 依据账号判断对账单调用接口(1-承保V3,2-退保)
     */
	public String stateInsureType = "";

    /**
     * 对账单单笔批量标志(single-单笔,bat-批量)
     */
	public String batFlag = "";

	private XmlTextReader xmlReader;
	public ReqQryStatement(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
		xmlReader = p_xmlReader;

		actNum = xmlReader.getSimpleText("ActNum");
		busDate = xmlReader.getSimpleText("BusDate");
		if (StringHelper.isNullOrEmpty(busDate)) {
			busDate = Format.Date8Format.format(Format.Date10Format.parse(xmlReader.getSimpleText("DateToday")));
		}
		
		statementType = xmlReader.getSimpleText("StatementType");
        stateInsureType = xmlReader.getSimpleText("StateInsureType");
		if (StringHelper.isNullOrEmpty(statementType)) {
			statementType = xmlReader.getSimpleText("MoneyWay");
			if (StringHelper.hasAnyChar(statementType)) {
                if ("1".equals(statementType)) {
                    statementType = "F";
                } else {
                    statementType = "S";
                }
            }
		}
        batFlag = xmlReader.getSimpleText("BatchFlag");
		channel = xmlReader.getSimpleText("Channel");
		askNumber = xmlReader.getSimpleText("ReqSeqID");
		statementNumber = xmlReader.getSimpleText("StatementNumber");
		higherLevelAct = xmlReader.getSimpleTextNotNull("HigherLevelAct");
	}
	
	public ReqQryStatement(ReqRespHeader p_header){
		reqHeader = p_header;
	}
	
	public Date getBusDate() throws ParseException{
		return Format.Date8Format.parse(busDate);
	}

	/*是否大于等于今天*/
	public boolean chkBusDate(){
		int intToday = Integer.parseInt(Format.Date8Format.format(new Date()));
		int intBusDate = Integer.parseInt(busDate);
		if(intToday>intBusDate){
			return true;
		}
		else{
			return false;
		}
	}
}
